import 'package:flutter/material.dart';
import 'package:flutter_xyf/pages/component/app_bar/index.dart';

class MyPage extends StatefulWidget {
  MyPage({Key? key}) : super(key: key);

  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  double appBarAlpha = 0;
  _onScroll(offset) {
    //print(offset);
    if (offset > 200) return;
    double alpha = offset / 200;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    setState(() {
      appBarAlpha = alpha;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset:
          false, // //默认值为true，表示页面上推， 设置false表示不上推，此时键盘可能会盖住页面，类似stack层叠效果
      appBar: AppBar(
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [Colors.cyan, Colors.blue, Colors.blueAccent],
            ),
          ),
        ),
        title: Text('我的'),
      ),
      body: Scrollbar(
        child: NotificationListener(
            onNotification: (scrollNotification) {
              if (scrollNotification is ScrollUpdateNotification) {
                if (scrollNotification.metrics.axis == Axis.vertical)
                  _onScroll(scrollNotification.metrics.pixels);
              }
              return false;
            },
            child: ListView(
              children: [
                Container(
                  height: 2000,
                  color: Colors.red,
                )
              ],
            )),
      ),
    );
  }
}
